<?php
namespace App\Services\Export;

use App\Services\Export\WordAbstract;

class WordArchives extends WordAbstract
{
    public function set($data = [],$imgData = [], $record = [])
    { 
        if(count($data)) {
            foreach($data as $k=>$v) {  
                $this->templateProcessor->setValue($k, $v);
              }
        }

        if(count($imgData)) {
            foreach ($imgData as $k => $v) {
                if(!empty($v)) {
                    if(is_array($v)){
                        $width = isset($v['width'])?$v['width']:80;
                        $height = isset($v['height'])?$v['height']:60;
                        $this->templateProcessor->setImageValue($k,
                                array('path' => $v['path'], 'width' => $width, 'height' => $height)
                            );
                    } else {
                        $this->templateProcessor->setImageValue($k,
                                array('path' => $v)
                            );
                    }
                } else {
                    $this->templateProcessor->setValue($k, '');
                }
            }  
        }
        foreach ($record as $key => $value) {
            if($key=='fire') {
                $this->templateProcessor->cloneRow('fireNumber', count($value));
                foreach ($value as $k => $v) {
                    foreach($v as $kk=>$vv) {
                        if($kk!=='fireDangerPicture'&&$kk!=='fireReformPicture') {
                            $this->templateProcessor->setValue($kk.'#'.$k, $vv);
                        } else {
                            if(!empty($vv)) {
                                 if(is_array($vv)){
                                    $path = $vv['path'];
                                    $width = isset($vv['width'])?$vv['width']:200;
                                    $height = isset($vv['height'])?$vv['height']:150;
                                } else {
                                    $path = $vv;
                                    $width = 200;
                                    $height = 150;
                                }
                                $this->templateProcessor->setImageValue($kk.'#'.$k,  array('path' => $path, 'width' => $width, 'height' => $height));
                            } else {
                                $this->templateProcessor->setValue($kk.'#'.$k, $vv);
                            }
                        }
                    }/*处理数据*/
                }/*处理表格数据*/  
            }
            if($key=='product') {
                $this->templateProcessor->cloneRow('productNumber', count($value));
                foreach ($value as $k => $v) {
                    foreach($v as $kk=>$vv) {
                        if($kk!=='productDangerPicture'&&$kk!=='productReformPicture') {
                            $this->templateProcessor->setValue($kk.'#'.$k, $vv);
                        } else {
                            if(!empty($vv)) {
                                if(is_array($vv)){
                                    $path = $vv['path'];
                                    $width = isset($vv['width'])?$vv['width']:200;
                                    $height = isset($vv['height'])?$vv['height']:150;
                                } else {
                                    $path = $vv;
                                    $width = 200;
                                    $height = 150;
                                }
                                $this->templateProcessor->setImageValue($kk.'#'.$k,  array('path' => $path, 'width' => $width, 'height' => $height));
                            } else {
                                $this->templateProcessor->setValue($kk.'#'.$k, $vv);
                            }
                        }
                    }/*处理数据*/
                }/*处理表格数据*/  
            }
           
        }

        $this->templateProcessor->setValue(array('fireNumber','fireCategory','fireDangerDescription','fireAccords','fireReformProposal','fireDangerPicture','fireReformStatus','fireReformPicture','fireRemark'),array('','','','','','','','',''));
        $this->templateProcessor->setValue(array('productNumber','productCategory','productDangerDescription','productAccords','productReformProposal','productDangerPicture','productReformStatus','productReformPicture','productRemark'),array('','','','','','','','',''));
    }
}